package com.zzmltc.hosp.controller.api;

import com.zzmltc.common.result.Result;
import com.zzmltc.hosp.controller.HospitalController;
import com.zzmltc.hosp.controller.HospitalSetController;
import com.zzmltc.hosp.service.DepartmentService;
import com.zzmltc.hosp.service.HospitalService;
import com.zzmltc.hosp.service.ScheduleService;
import com.zzmstc.model.hosp.Hospital;
import com.zzmstc.model.hosp.Schedule;
import com.zzmstc.vo.hosp.DepartmentVo;
import com.zzmstc.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/hosp/hospital")
@Api(tags = "医院前台预约API接口")
public class HaspApiController {
    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation(value = "查询医院列表")
    @GetMapping("findHospList/{page}/{limit}")
    public Result findHospList(@PathVariable Integer page,
                               @PathVariable Integer limit,
                               HospitalQueryVo hospitalQueryVo)
    {
        Page<Hospital> hospitals = hospitalService.selectHospPage(page, limit, hospitalQueryVo);
        List<Hospital> content = hospitals.getContent();
        int totalPages = hospitals.getTotalPages();
        return Result.ok(hospitals);
    }

    @ApiOperation(value = "根据医院名称查询医院")
    @GetMapping("findByHosName/{hosname}")
    public Result findByHosName(@PathVariable String hosname){
        List<Hospital> list =hospitalService.findByHosname(hosname);
        return Result.ok(list);

    }
    @ApiOperation(value = "根据医院编号获取科室列表")
    @GetMapping("department/{hoscode}")
    public Result index(@PathVariable String hoscode) {
        List<DepartmentVo> deptTree = departmentService.findDeptTree(hoscode);
        return Result.ok(deptTree);
    }
    //根据医院编号获取医院预约挂号详情
    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("findHospDetail/{hoscode}")
    public Result item(@PathVariable String hoscode) {
        Map<String, Object> map=hospitalService.item(hoscode);
        return Result.ok(map);
    }
//获取可预约排班数量
    @ApiOperation(value = "获取可预约排班数量")
    @GetMapping("auth/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public Result getBookingSchedule(@PathVariable Integer page,
                                     @PathVariable Integer limit,
                                     @PathVariable String hoscode,
                                     @PathVariable String depcode
                                     ){
        Map<String, Object> schedulepage=scheduleService.getBookingSchedule(page, limit, hoscode,depcode);
        return Result.ok(schedulepage);
    }
//    获取排班接口
    @ApiOperation(value = "获取排班接口")
    @GetMapping("auth/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public Result findScheduleList(
            @ApiParam(name = "hoscode",value = "医院code",required = true)
            @PathVariable String hoscode,
            @ApiParam(name = "depcode",value = "科室code",required = true)
            @PathVariable String depcode,
            @ApiParam(name = "workDate",value = "排班日趋",required = true)
            @PathVariable String workDate)
    {
        List<Schedule> detailSchedule = scheduleService.getDetailSchedule(hoscode, depcode, workDate);
        return Result.ok(detailSchedule);
    }
    @ApiOperation(value = "根据排班id获取排班数据")
    @GetMapping("getSchedule/{scheduleId}")
    public Result getSchedule(@PathVariable String scheduleId){
        Schedule schedule=scheduleService.getScheduleId(scheduleId);
        return Result.ok(schedule);

    }
}
